{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import tensorflow.keras as keras\n",
    "import tensorflow.keras.layers as layers\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "openD = pd.read_csv('data/open.csv', header = None)\n",
    "closeD = pd.read_csv('data/close.csv', header = None)\n",
    "silenceD = pd.read_csv('data/silence.csv', header = None)\n",
    "print(openD)\n",
    "print(closeD)\n",
    "print(silenceD)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "SAMPLES_PER_VOICE = 30\n",
    "FEATURE_NUM = 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def processData(d, v):\n",
    "    dataX = np.empty([0,SAMPLES_PER_VOICE*FEATURE_NUM])\n",
    "    dataY = np.empty([0])\n",
    "\n",
    "    data  = d.values\n",
    "    dataNum = data.shape[0] // SAMPLES_PER_VOICE\n",
    "\n",
    "    for i in tqdm(range(dataNum)):\n",
    "        tmp = []\n",
    "        for j in range(SAMPLES_PER_VOICE):\n",
    "            tmp += [data[i * SAMPLES_PER_VOICE + j][0] / 128.0]\n",
    "            tmp += [data[i * SAMPLES_PER_VOICE + j][1] / 128.0]\n",
    "            tmp += [data[i * SAMPLES_PER_VOICE + j][2] / 128.0]\n",
    "            tmp += [data[i * SAMPLES_PER_VOICE + j][3] / 128.0]\n",
    "            tmp += [data[i * SAMPLES_PER_VOICE + j][4] / 128.0]\n",
    "            tmp += [data[i * SAMPLES_PER_VOICE + j][5] / 128.0]\n",
    "            tmp += [data[i * SAMPLES_PER_VOICE + j][6] / 128.0]\n",
    "            tmp += [data[i * SAMPLES_PER_VOICE + j][7] / 128.0]\n",
    "\n",
    "        tmp = np.array(tmp)\n",
    "        tmp = np.expand_dims(tmp, axis = 0)\n",
    "\n",
    "        dataX = np.concatenate((dataX, tmp), axis = 0)\n",
    "        dataY = np.append(dataY, v)\n",
    "\n",
    "    return dataX, dataY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 100/100 [00:00<00:00, 3843.19it/s]\n",
      "100%|██████████| 100/100 [00:00<00:00, 4836.72it/s]\n",
      "100%|██████████| 100/100 [00:00<00:00, 4969.73it/s]\n"
     ]
    }
   ],
   "source": [
    "silenceX, silenceY = processData(silenceD, 0)\n",
    "openX, openY = processData(openD, 1)\n",
    "closeX, closeY = processData(closeD, 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.        0.        0.        ... 0.        0.        0.       ]\n",
      " [0.0078125 0.        0.        ... 0.        0.        0.       ]\n",
      " [0.        0.        0.        ... 0.        0.        0.       ]\n",
      " ...\n",
      " [0.171875  0.4140625 0.2265625 ... 0.        0.        0.       ]\n",
      " [0.171875  0.5546875 0.2578125 ... 0.        0.        0.       ]\n",
      " [0.0390625 0.15625   0.2890625 ... 0.        0.        0.       ]]\n",
      "[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
      " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
      " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
      " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n",
      " 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n",
      " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n",
      " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n",
      " 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.\n",
      " 1. 1. 1. 1. 1. 1. 1. 1. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.\n",
      " 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.\n",
      " 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.\n",
      " 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.\n",
      " 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]\n"
     ]
    }
   ],
   "source": [
    "dataX = np.concatenate((silenceX, openX), axis = 0)\n",
    "dataY = np.append(silenceY, openY)\n",
    "dataX = np.concatenate((dataX, closeX), axis = 0)\n",
    "dataY = np.append(dataY, closeY)\n",
    "print(dataX)\n",
    "print(dataY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 73  71 115  57  27  60 192 248 195 124  87 119 135 197 246  80 294 134\n",
      "  99 147 245 236   8 188  41   2 139 219  52 218 174 128 149  45 263 165\n",
      "  16   9 242   6 222 201  37 109 261  77 131 277  17 207  22 104  30  34\n",
      " 284 198 121 223 105 264 127 235 179  31 133 186 271 280 107 297 120 185\n",
      " 102 156  32  29  66 225 166  51 232  89 184 118 213  79 295 114 285  69\n",
      " 228 215 191  74 227  93 258 292  86 137 164 256 168 239   5 194  39  72\n",
      " 299 155  42 287  55 289 180   1 281  92 160  20  96 161 253 262  46 106\n",
      " 113 254  33 247  58   0 202 278  88  68  50 272 150 162 282 169  78 152\n",
      " 163 199 126 229 171 111  81   3 190 231 144 293 276   4  62  48 230  67\n",
      "  91 237 112 110 183  14  98 273 243 288 142 259 143 217 132 274 129 170\n",
      " 267 226 212 251 130 298  82 257 220  15 116  40 290 136 117  38 158 122\n",
      "   7 244  12 252  24 182 204  64 221 101 291 269  83 151  44 159  59  10\n",
      " 108 138  54 205  19 250  56 206 216 210  65  26 189 249 266  76 255 270\n",
      "  13  90 214 154 268  43 283 140  47 177  84  53 157 172 275 176  49 141\n",
      " 209 296 196 241 286 240  11  63 233  97  36 193 100 153  75 148 238 175\n",
      "  85  61 265  35 211 203 123 279  94  25  70  23 173  95 125 181  18 146\n",
      " 234 145 224  28  21 103 208 167 260 200 187 178]\n"
     ]
    }
   ],
   "source": [
    "permutationTrain = np.random.permutation(dataX.shape[0])\n",
    "print(permutationTrain)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0. 0. 1. 0. 0. 0. 1. 2. 1. 1. 0. 1. 1. 1. 2. 0. 2. 1. 0. 1. 2. 2. 0. 1.\n",
      " 0. 0. 1. 2. 0. 2. 1. 1. 1. 0. 2. 1. 0. 0. 2. 0. 2. 2. 0. 1. 2. 0. 1. 2.\n",
      " 0. 2. 0. 1. 0. 0. 2. 1. 1. 2. 1. 2. 1. 2. 1. 0. 1. 1. 2. 2. 1. 2. 1. 1.\n",
      " 1. 1. 0. 0. 0. 2. 1. 0. 2. 0. 1. 1. 2. 0. 2. 1. 2. 0. 2. 2. 1. 0. 2. 0.\n",
      " 2. 2. 0. 1. 1. 2. 1. 2. 0. 1. 0. 0. 2. 1. 0. 2. 0. 2. 1. 0. 2. 0. 1. 0.\n",
      " 0. 1. 2. 2. 0. 1. 1. 2. 0. 2. 0. 0. 2. 2. 0. 0. 0. 2. 1. 1. 2. 1. 0. 1.\n",
      " 1. 1. 1. 2. 1. 1. 0. 0. 1. 2. 1. 2. 2. 0. 0. 0. 2. 0. 0. 2. 1. 1. 1. 0.\n",
      " 0. 2. 2. 2. 1. 2. 1. 2. 1. 2. 1. 1. 2. 2. 2. 2. 1. 2. 0. 2. 2. 0. 1. 0.\n",
      " 2. 1. 1. 0. 1. 1. 0. 2. 0. 2. 0. 1. 2. 0. 2. 1. 2. 2. 0. 1. 0. 1. 0. 0.\n",
      " 1. 1. 0. 2. 0. 2. 0. 2. 2. 2. 0. 0. 1. 2. 2. 0. 2. 2. 0. 0. 2. 1. 2. 0.\n",
      " 2. 1. 0. 1. 0. 0. 1. 1. 2. 1. 0. 1. 2. 2. 1. 2. 2. 2. 0. 0. 2. 0. 0. 1.\n",
      " 1. 1. 0. 1. 2. 1. 0. 0. 2. 0. 2. 2. 1. 2. 0. 0. 0. 0. 1. 0. 1. 1. 0. 1.\n",
      " 2. 1. 2. 0. 0. 1. 2. 1. 2. 2. 1. 1.]\n"
     ]
    }
   ],
   "source": [
    "dataX = dataX[permutationTrain]\n",
    "dataY = dataY[permutationTrain]\n",
    "print(dataY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "vfoldSize = int(dataX.shape[0]/100*20)\n",
    "\n",
    "xTest = dataX[0:vfoldSize]\n",
    "yTest = dataY[0:vfoldSize]\n",
    "\n",
    "xTrain = dataX[vfoldSize:dataX.shape[0]]\n",
    "yTrain = dataY[vfoldSize:dataY.shape[0]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = keras.Sequential()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.add(keras.layers.Dense(32, input_shape =(FEATURE_NUM*SAMPLES_PER_VOICE,), activation='relu'))\n",
    "model.add(keras.layers.Dense(16, activation='relu'))\n",
    "model.add(keras.layers.Dense(3, activation='softmax'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "adam = keras.optimizers.Adam(0.00001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.compile(loss='sparse_categorical_crossentropy',\n",
    "              optimizer=adam,\n",
    "              metrics=['sparse_categorical_accuracy'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "dense (Dense)                (None, 32)                7712      \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 16)                528       \n",
      "_________________________________________________________________\n",
      "dense_2 (Dense)              (None, 3)                 51        \n",
      "=================================================================\n",
      "Total params: 8,291\n",
      "Trainable params: 8,291\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 240 samples, validate on 60 samples\n",
      "Epoch 1/200\n",
      "240/240 [==============================] - 2s 7ms/sample - loss: 1.1167 - sparse_categorical_accuracy: 0.2125 - val_loss: 1.1214 - val_sparse_categorical_accuracy: 0.3167\n",
      "Epoch 2/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 1.1066 - sparse_categorical_accuracy: 0.3875 - val_loss: 1.1111 - val_sparse_categorical_accuracy: 0.4667\n",
      "Epoch 3/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 1.0957 - sparse_categorical_accuracy: 0.5667 - val_loss: 1.0998 - val_sparse_categorical_accuracy: 0.5667\n",
      "Epoch 4/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 1.0843 - sparse_categorical_accuracy: 0.6500 - val_loss: 1.0885 - val_sparse_categorical_accuracy: 0.6167\n",
      "Epoch 5/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 1.0725 - sparse_categorical_accuracy: 0.6833 - val_loss: 1.0766 - val_sparse_categorical_accuracy: 0.6833\n",
      "Epoch 6/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 1.0605 - sparse_categorical_accuracy: 0.7125 - val_loss: 1.0650 - val_sparse_categorical_accuracy: 0.7167\n",
      "Epoch 7/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 1.0487 - sparse_categorical_accuracy: 0.7333 - val_loss: 1.0534 - val_sparse_categorical_accuracy: 0.7500\n",
      "Epoch 8/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 1.0369 - sparse_categorical_accuracy: 0.7750 - val_loss: 1.0421 - val_sparse_categorical_accuracy: 0.7500\n",
      "Epoch 9/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 1.0254 - sparse_categorical_accuracy: 0.8125 - val_loss: 1.0312 - val_sparse_categorical_accuracy: 0.8167\n",
      "Epoch 10/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 1.0147 - sparse_categorical_accuracy: 0.8583 - val_loss: 1.0211 - val_sparse_categorical_accuracy: 0.8833\n",
      "Epoch 11/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 1.0039 - sparse_categorical_accuracy: 0.9042 - val_loss: 1.0112 - val_sparse_categorical_accuracy: 0.9500\n",
      "Epoch 12/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.9931 - sparse_categorical_accuracy: 0.9292 - val_loss: 1.0012 - val_sparse_categorical_accuracy: 0.9500\n",
      "Epoch 13/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.9824 - sparse_categorical_accuracy: 0.9625 - val_loss: 0.9913 - val_sparse_categorical_accuracy: 0.9500\n",
      "Epoch 14/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.9717 - sparse_categorical_accuracy: 0.9875 - val_loss: 0.9814 - val_sparse_categorical_accuracy: 0.9667\n",
      "Epoch 15/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.9608 - sparse_categorical_accuracy: 0.9875 - val_loss: 0.9713 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 16/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.9498 - sparse_categorical_accuracy: 0.9875 - val_loss: 0.9609 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 17/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.9388 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.9506 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 18/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.9278 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.9401 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 19/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.9167 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.9298 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 20/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.9056 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.9194 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 21/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.8945 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.9089 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 22/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.8834 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8984 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 23/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.8723 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8881 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 24/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.8612 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8777 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 25/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.8500 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8672 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 26/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.8388 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8567 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 27/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.8276 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8461 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 28/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.8162 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8352 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 29/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.8048 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8244 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 30/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.7934 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8137 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 31/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.7820 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.8027 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 32/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.7706 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.7919 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 33/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.7593 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.7811 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 34/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.7480 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.7703 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 35/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.7368 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.7595 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 36/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.7256 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.7488 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 37/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.7146 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.7381 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 38/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.7035 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.7275 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 39/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.6926 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.7169 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 40/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.6817 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.7064 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 41/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.6709 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6960 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 42/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.6601 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6856 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 43/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.6495 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6751 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 44/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.6389 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6648 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 45/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.6284 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6545 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 46/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.6180 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6445 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 47/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.6077 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6345 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 48/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.5975 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6245 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 49/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.5875 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6145 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 50/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.5774 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.6047 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 51/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.5675 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5948 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 52/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.5577 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5851 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 53/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.5479 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5755 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 54/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.5383 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5660 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 55/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.5287 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5565 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 56/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.5193 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5470 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 57/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.5098 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5377 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 58/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.5005 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5284 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 59/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4913 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5191 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 60/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4821 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5100 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 61/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4729 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.5008 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 62/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4639 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4919 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 63/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4551 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4830 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 64/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4463 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4741 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 65/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4376 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4653 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 66/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4289 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4564 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 67/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4204 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4478 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 68/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.4120 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4392 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 69/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.4037 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4307 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 70/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.3955 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4223 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 71/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.3872 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4139 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 72/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.3792 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.4056 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 73/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.3712 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3974 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 74/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.3634 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3893 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 75/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.3557 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3813 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 76/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.3481 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3734 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 77/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.3406 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3655 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 78/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.3332 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3577 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 79/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.3260 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3501 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 80/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.3189 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3425 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 81/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.3120 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3352 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 82/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.3051 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3280 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 83/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2984 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3209 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 84/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2919 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3139 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 85/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.2854 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3071 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 86/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.2791 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.3004 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 87/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.2730 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2937 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 88/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.2669 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2873 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 89/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2610 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2809 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 90/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2552 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2747 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 91/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2494 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2686 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 92/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2438 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2626 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 93/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2383 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2567 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 94/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2329 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2509 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 95/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2277 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2452 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 96/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2225 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2397 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 97/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2174 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2342 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 98/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.2124 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2288 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 99/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2076 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2235 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 100/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.2028 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2183 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 101/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1981 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2132 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 102/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1935 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2083 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 103/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1890 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.2033 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 104/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.1846 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1986 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 105/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.1803 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1939 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 106/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1760 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1893 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 107/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1719 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1847 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 108/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1679 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1803 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 109/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.1639 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1760 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 110/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.1600 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1717 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 111/200\n",
      "240/240 [==============================] - ETA: 0s - loss: 0.1541 - sparse_categorical_accuracy: 0.995 - 1s 3ms/sample - loss: 0.1563 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1677 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 112/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.1525 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1635 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 113/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1489 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1595 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 114/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1453 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1557 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 115/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1418 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1518 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 116/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1384 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1481 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 117/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1351 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1445 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 118/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1319 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1409 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 119/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1287 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1374 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 120/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1256 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1340 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 121/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1226 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1307 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 122/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1196 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1275 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 123/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1167 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1243 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 124/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1139 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1211 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 125/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1112 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1182 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 126/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1085 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1153 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 127/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1059 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1123 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 128/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1033 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1096 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 129/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.1009 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1068 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 130/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0985 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1042 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 131/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0961 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.1016 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 132/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0938 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0990 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 133/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0915 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0965 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 134/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0894 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0941 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 135/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0872 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0918 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 136/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0851 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0895 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 137/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0831 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0872 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 138/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0811 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0851 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 139/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0792 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0829 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 140/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0773 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0809 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 141/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0755 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0789 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 142/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0737 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0769 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 143/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0720 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0750 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 144/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0703 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0732 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 145/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0687 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0714 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 146/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0671 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0696 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 147/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0655 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0679 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 148/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0640 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0663 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 149/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0626 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0647 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 150/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0612 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0631 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 151/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0598 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0616 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 152/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0584 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0601 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 153/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0571 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0587 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 154/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0559 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0572 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 155/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0546 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0559 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 156/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0534 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0545 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 157/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0522 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0533 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 158/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0511 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0520 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 159/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0501 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0508 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 160/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0489 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0496 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 161/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0479 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0485 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 162/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0469 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0474 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 163/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0459 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0463 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 164/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0449 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0453 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 165/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0440 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0443 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 166/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0431 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0431 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 167/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0422 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0423 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 168/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0413 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0413 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 169/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0405 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0404 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 170/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0397 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0396 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 171/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0389 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0387 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 172/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0381 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0379 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 173/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0373 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0371 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 174/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0366 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0363 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 175/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0359 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0355 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 176/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0352 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0347 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 177/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0346 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0340 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 178/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0339 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0333 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 179/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0332 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0326 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 180/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0326 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0320 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 181/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0320 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0312 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 182/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0314 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0306 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 183/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0309 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0300 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 184/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0303 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0295 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 185/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0298 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0288 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 186/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0293 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0283 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 187/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0287 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0278 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 188/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0282 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0272 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 189/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0277 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0267 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 190/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0273 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0262 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 191/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0268 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0257 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 192/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0264 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0252 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 193/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0259 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0248 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 194/200\n",
      "240/240 [==============================] - 1s 4ms/sample - loss: 0.0255 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0244 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 195/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0251 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0239 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 196/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0246 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0235 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 197/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0243 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0231 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 198/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0239 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0226 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 199/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0235 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0223 - val_sparse_categorical_accuracy: 1.0000\n",
      "Epoch 200/200\n",
      "240/240 [==============================] - 1s 3ms/sample - loss: 0.0231 - sparse_categorical_accuracy: 0.9958 - val_loss: 0.0219 - val_sparse_categorical_accuracy: 1.0000\n"
     ]
    }
   ],
   "source": [
    "history = model.fit(xTrain, yTrain, batch_size=1, validation_data=(xTest, yTest), epochs=200, verbose=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "34744"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "converter = tf.lite.TFLiteConverter.from_keras_model(model)\n",
    "tflite_model = converter.convert()\n",
    "\n",
    "open(\"model\", \"wb\").write(tflite_model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "!xxd -i model >> model.h"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
